package net.proef.sample.domain;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("book")
public class Book {

	private String isbn;
	private String title;
	private int edition;
	private int pages;
	private String published;
	private List<Author> authors;
	private Publisher publisher;

	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public String getPublished() {
		return published;
	}

	public void setPublished(String published) {
		this.published = published;
	}

	public Publisher getPublisher() {
		return publisher;
	}

	public void setPublisher(Publisher publisher) {
		this.publisher = publisher;
	}

	public void setAuthors(List<Author> authors) {
		this.authors = new LinkedList<Author>(authors);
	}

	public List<Author> getAuthors() {
		return new LinkedList<Author>(authors);
	}

	public void setEdition(int edition) {
		this.edition = edition;
	}

	public int getEdition() {
		return edition;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
				.appendSuper(super.toString()).append("title", this.title)
				.append("publisher", this.publisher).append("by", this.authors)
				.toString();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(13, 1).append(this.isbn).append(this.title)
				.append(this.edition).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Book) {
			Book b = (Book) obj;
			return new EqualsBuilder().append(this.isbn, b.isbn)
					.append(this.title, b.title)
					.append(this.edition, b.edition).isEquals();
		}

		return false;
	}
}